

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.table.DefaultTableModel;
import javax.swing.JScrollPane;
import java.awt.BorderLayout;

import javax.swing.BoxLayout;
import javax.swing.ImageIcon;

import java.awt.GridBagLayout;
import java.awt.FlowLayout;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JTable;
import javax.swing.JComboBox;
import java.awt.GridBagConstraints;
import java.awt.Insets;

import javax.swing.JTextArea;

public class ProductMaintenanceFrame extends JFrame {

	private JPanel contentPane;
	private JTextField GdNmField;
	private JTextField TimeField;
	private JTextField textField;
	private JTextField textField_1;
	private JTextField textField_2;
	private JTextField textField_3;
	private JTextField textField_4;
	private JTextField textField_5;
	private JTextField textField_6;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					ProductMaintenanceFrame frame = new ProductMaintenanceFrame();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public ProductMaintenanceFrame() {
		setTitle("商品维护");
		//设置窗体位置与大小
		setBounds(100, 100, 450, 300);
		//设置关闭操作的事件
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		//固定窗口大小
		setSize(800,600);
		//设置窗口的位置为居中显示
		setLocationRelativeTo(null);
		getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));
		
		//第一布局
		JPanel searchpanel = new JPanel();  
		getContentPane().add(searchpanel);
		searchpanel.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
		
		JLabel GdNmLabel = new JLabel("商品名称");
		searchpanel.add(GdNmLabel);
		
		GdNmField = new JTextField();
		searchpanel.add(GdNmField);
		GdNmField.setColumns(10);
		
		JLabel TimeLable = new JLabel("生产日期");
		searchpanel.add(TimeLable);
		
		TimeField = new JTextField();
		searchpanel.add(TimeField);
		TimeField.setColumns(10);
		
		JLabel TypeLabel = new JLabel("商品类别");
		searchpanel.add(TypeLabel);
		
		JComboBox comboBox = new JComboBox();
		comboBox.addItem("请选择..."); //向下拉列表中添加一项
		comboBox.addItem("食品类");
		comboBox.addItem("书本类");
		comboBox.addItem("手机类");
		comboBox.addItem("电脑类");
		comboBox.addItem("服装类");
		searchpanel.add(comboBox);
		
		JButton btnNewButton = new JButton("查询");
		btnNewButton.setIcon(new ImageIcon("./images/search.png"));
		searchpanel.add(btnNewButton);
		

		//第二布局
		JPanel table = new JPanel();
		getContentPane().add(table);
		
		JScrollPane numbertwo = new JScrollPane();
		getContentPane().add(numbertwo, BorderLayout.SOUTH);
		String[] columnNames = {"编号","商品名称","生产日期","商品价格","商品描述","商品类别"};
		Object[][] data= {{"2","OX手机","2024/5/9","2666.0","5G手机遥遥领先","手机类"},
				{"3","苹果","2024/6/19","2.0","水果新上市","水果类"},
				{"4","华为笔记本电脑","2022/5/12","4358.0","电脑","电脑类"},
				};
		
		DefaultTableModel model=new DefaultTableModel(data,columnNames);
		JTable table1=new JTable(model);
		JScrollPane tablePanel=new JScrollPane(table1);
		getContentPane().add(tablePanel);
		
		
		
		// 第三布局
		JPanel presspanel = new JPanel();
		getContentPane().add(presspanel, BorderLayout.WEST);
		GridBagLayout gbl_numberthree = new GridBagLayout();
		gbl_numberthree.rowWeights = new double[]{0.0, 0.0, 0.0, 1.0};
		gbl_numberthree.columnWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0};
		presspanel.setLayout(gbl_numberthree);
		
		JLabel lblNewLabel = new JLabel("编号");
		GridBagConstraints gbc_lblNewLabel = new GridBagConstraints();
		gbc_lblNewLabel.anchor = GridBagConstraints.EAST;
		gbc_lblNewLabel.insets = new Insets(0, 0, 5, 5);
		gbc_lblNewLabel.gridx = 1;
		gbc_lblNewLabel.gridy = 0;
		presspanel.add(lblNewLabel, gbc_lblNewLabel);
		
		textField_1 = new JTextField();
		GridBagConstraints gbc_textField_1 = new GridBagConstraints();
		gbc_textField_1.insets = new Insets(0, 0, 5, 5);
		gbc_textField_1.fill = GridBagConstraints.HORIZONTAL;
		gbc_textField_1.gridx = 2;
		gbc_textField_1.gridy = 0;
		presspanel.add(textField_1, gbc_textField_1);
		textField_1.setColumns(10);
		
		JLabel lblNewLabel_1 = new JLabel("商品名称");
		GridBagConstraints gbc_lblNewLabel_1 = new GridBagConstraints();
		gbc_lblNewLabel_1.anchor = GridBagConstraints.EAST;
		gbc_lblNewLabel_1.insets = new Insets(0, 0, 5, 5);
		gbc_lblNewLabel_1.gridx = 3;
		gbc_lblNewLabel_1.gridy = 0;
		presspanel.add(lblNewLabel_1, gbc_lblNewLabel_1);
		
		textField_3 = new JTextField();
		GridBagConstraints gbc_textField_3 = new GridBagConstraints();
		gbc_textField_3.insets = new Insets(0, 0, 5, 5);
		gbc_textField_3.fill = GridBagConstraints.HORIZONTAL;
		gbc_textField_3.gridx = 4;
		gbc_textField_3.gridy = 0;
		presspanel.add(textField_3, gbc_textField_3);
		textField_3.setColumns(10);
		
		JLabel lblNewLabel_5 = new JLabel("商品类别");
		GridBagConstraints gbc_lblNewLabel_5 = new GridBagConstraints();
		gbc_lblNewLabel_5.insets = new Insets(0, 0, 5, 5);
		gbc_lblNewLabel_5.gridx = 8;
		gbc_lblNewLabel_5.gridy = 0;
		presspanel.add(lblNewLabel_5, gbc_lblNewLabel_5);
		
		JTextArea textArea = new JTextArea();
		GridBagConstraints gbc_textArea = new GridBagConstraints();
		gbc_textArea.insets = new Insets(0, 0, 5, 0);
		gbc_textArea.gridwidth = 3;
		gbc_textArea.gridheight = 3;
		gbc_textArea.fill = GridBagConstraints.BOTH;
		gbc_textArea.gridx = 9;
		gbc_textArea.gridy = 0;
		presspanel.add(textArea, gbc_textArea);
		
		JLabel lblNewLabel_3 = new JLabel("商品描述");
		GridBagConstraints gbc_lblNewLabel_3 = new GridBagConstraints();
		gbc_lblNewLabel_3.anchor = GridBagConstraints.EAST;
		gbc_lblNewLabel_3.insets = new Insets(0, 0, 5, 5);
		gbc_lblNewLabel_3.gridx = 1;
		gbc_lblNewLabel_3.gridy = 2;
		presspanel.add(lblNewLabel_3, gbc_lblNewLabel_3);
		
		textField_4 = new JTextField();
		GridBagConstraints gbc_textField_4 = new GridBagConstraints();
		gbc_textField_4.insets = new Insets(0, 0, 5, 5);
		gbc_textField_4.fill = GridBagConstraints.HORIZONTAL;
		gbc_textField_4.gridx = 2;
		gbc_textField_4.gridy = 2;
		presspanel.add(textField_4, gbc_textField_4);
		textField_4.setColumns(10);
		
		JLabel lblNewLabel_4 = new JLabel("生产日期");
		GridBagConstraints gbc_lblNewLabel_4 = new GridBagConstraints();
		gbc_lblNewLabel_4.anchor = GridBagConstraints.EAST;
		gbc_lblNewLabel_4.insets = new Insets(0, 0, 5, 5);
		gbc_lblNewLabel_4.gridx = 3;
		gbc_lblNewLabel_4.gridy = 2;
		presspanel.add(lblNewLabel_4, gbc_lblNewLabel_4);
		
		
		textField_5 = new JTextField();
		GridBagConstraints gbc_textField_5 = new GridBagConstraints();
		gbc_textField_5.insets = new Insets(0, 0, 5, 5);
		gbc_textField_5.fill = GridBagConstraints.HORIZONTAL;
		gbc_textField_5.gridx = 4;
		gbc_textField_5.gridy = 2;
		presspanel.add(textField_5, gbc_textField_5);
		textField_5.setColumns(10);
		
		JLabel lblNewLabel_6 = new JLabel("生产日期");
		GridBagConstraints gbc_lblNewLabel_6 = new GridBagConstraints();
		gbc_lblNewLabel_6.anchor = GridBagConstraints.EAST;
		gbc_lblNewLabel_6.insets = new Insets(0, 0, 5, 5);
		gbc_lblNewLabel_6.gridx = 6;
		gbc_lblNewLabel_6.gridy = 2;
		presspanel.add(lblNewLabel_6, gbc_lblNewLabel_6);
		
		JComboBox cmb = new JComboBox();
		cmb.addItem("食品类"); //向下拉列表中添加一项
		GridBagConstraints gbc_cmb = new GridBagConstraints();
		gbc_cmb.insets = new Insets(0, 0, 5, 5);
		gbc_cmb.fill = GridBagConstraints.HORIZONTAL;
		gbc_cmb.gridx = 7;
		gbc_cmb.gridy = 2;
		presspanel.add(cmb, gbc_cmb);
		
		
		JButton btnNewButton1 = new JButton("修改");
		GridBagConstraints gbc_btnNewButton = new GridBagConstraints();
		gbc_btnNewButton.insets = new Insets(0, 0, 0, 5);
		gbc_btnNewButton.gridx = 2;
		gbc_btnNewButton.gridy = 3;
		presspanel.add(btnNewButton1, gbc_btnNewButton);
		
		JButton btnNewButton2 = new JButton("删除");
		btnNewButton2.setIcon(new ImageIcon("./images/delete.png"));
		GridBagConstraints gbc_btnNewButton2 = new GridBagConstraints();
		gbc_btnNewButton2.insets = new Insets(0, 0, 0, 5);
		gbc_btnNewButton2.gridx = 4;
		gbc_btnNewButton2.gridy = 3;
		presspanel.add(btnNewButton2, gbc_btnNewButton2);
		
	}

}
